package com.org.api.admin.controller;

import com.alibaba.fastjson.JSON;
import com.org.api.admin.entity.po.*;
import com.org.platform.model.ResultModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description
 * @auther dh
 * @date 2022/2/28 13:47
 */

@Slf4j
@RestController
@RequestMapping(value = "/api/admin/test/cmsIndex")
public class CmsUserIndexController {

	@RequestMapping(value = {"/index"}, method = RequestMethod.GET)
	public ResultModel index() {


		CmsUserMobileIndexVO cmsUserMobileIndexVO = new CmsUserMobileIndexVO();


		/**
		 * 导航栏
		 */

		CmsUserMobileNavigationVO cmsMobileNavigation = new CmsUserMobileNavigationVO();
		cmsMobileNavigation.setModuleType("1");
		cmsMobileNavigation.setOrderSort(1);
		CmsUserMobileNavigationDetailVO cmsUserMobileNavigationDetailVO = new CmsUserMobileNavigationDetailVO();
		cmsUserMobileNavigationDetailVO.setConfigId(1L);
		cmsUserMobileNavigationDetailVO.setTitle("测试导航");
		cmsUserMobileNavigationDetailVO.setNavType("1");
		cmsUserMobileNavigationDetailVO.setOrderSort(1);
		cmsMobileNavigation.addModuleData(cmsUserMobileNavigationDetailVO);
		cmsUserMobileNavigationDetailVO = new CmsUserMobileNavigationDetailVO();
		cmsUserMobileNavigationDetailVO.setConfigId(2L);
		cmsUserMobileNavigationDetailVO.setTitle("测试导航2");
		cmsUserMobileNavigationDetailVO.setNavType("2");
		cmsUserMobileNavigationDetailVO.setOrderSort(2);
		cmsMobileNavigation.addModuleData(cmsUserMobileNavigationDetailVO);


		/**
		 * 轮播图
		 */
		CmsUserMobileBannerVO cmsMobileBannerVO = new CmsUserMobileBannerVO();
		cmsMobileBannerVO.setModuleType("2");
		cmsMobileBannerVO.setOrderSort(2);
		CmsUserMobileBannerDetailVO cmsUserMobileBannerDetailVO = new CmsUserMobileBannerDetailVO();
		cmsUserMobileBannerDetailVO.setPictureUrl("http://www.baidu.com");
		cmsUserMobileBannerDetailVO.setLinkType(1);
		cmsUserMobileBannerDetailVO.setLinkUrl("http://商品详情页");
		cmsUserMobileBannerDetailVO.setIsDefaultBackground(0);
		cmsUserMobileBannerDetailVO.setDefaultBackgroundUrl("http://图片地址");
		cmsUserMobileBannerDetailVO.setOrderSort(1);
		cmsMobileBannerVO.addModuleData(cmsUserMobileBannerDetailVO);
		cmsUserMobileBannerDetailVO = new CmsUserMobileBannerDetailVO();
		cmsUserMobileBannerDetailVO.setPictureUrl("http://www.hao123.com");
		cmsUserMobileBannerDetailVO.setLinkType(4);
		cmsUserMobileBannerDetailVO.setLinkUrl("阿莫西林");
		cmsUserMobileBannerDetailVO.setIsDefaultBackground(0);
		cmsUserMobileBannerDetailVO.setDefaultBackgroundUrl("http://图片地址");
		cmsUserMobileBannerDetailVO.setOrderSort(2);
		cmsMobileBannerVO.addModuleData(cmsUserMobileBannerDetailVO);


		/**
		 * 图文导航
		 */
		CmsUserMobileGraphicNavigationVO cmsMobileGraphicNavigation = new CmsUserMobileGraphicNavigationVO();
		cmsMobileGraphicNavigation.setModuleType("3");
		cmsMobileGraphicNavigation.setOrderSort(3);
		CmsUserMobileGraphicNavigationDetailVO cmsUserMobileGraphicNavigationDetailVO = new CmsUserMobileGraphicNavigationDetailVO();
		cmsUserMobileGraphicNavigationDetailVO.setTitle("图文导航1");
		cmsUserMobileGraphicNavigationDetailVO.setPictureUrl("http://www.baidu.com");
		cmsUserMobileGraphicNavigationDetailVO.setLinkType(1);
		cmsUserMobileGraphicNavigationDetailVO.setLinkUrl("商品详情页");
		cmsUserMobileGraphicNavigationDetailVO.setOrderSort(1);
		cmsMobileGraphicNavigation.addModuleData(cmsUserMobileGraphicNavigationDetailVO);


		/**
		 * 动态模板
		 */
		// 专场模块
		CmsUserSpecialPerformanceVO cmsMobileSpecialPerformance = CmsUserSpecialPerformanceVO.getData("专场名称", "http://image.com", 1, "选择商品地址", 2, "内部连接地址", 3, "搜索列表", 4, "专题", "4");
		cmsMobileSpecialPerformance.setModuleType("4");
		cmsMobileSpecialPerformance.setOrderSort(4);


		// 秒杀模块
		CmsUserMobileSeckillVO cmsMobileSeckill = new CmsUserMobileSeckillVO();
		cmsMobileSeckill.setEndTime("1646096260000");
		cmsMobileSeckill.setModuleType("5");
		cmsMobileSeckill.setOrderSort(5);
		CmsUserMobileSeckillDetailVO cmsUserMobileSeckillDetailVO = new CmsUserMobileSeckillDetailVO();
		cmsUserMobileSeckillDetailVO.setItemStoreId(1L);
		cmsUserMobileSeckillDetailVO.setOrderSort(1);
		cmsMobileSeckill.addModuleData(cmsUserMobileSeckillDetailVO);
		cmsUserMobileSeckillDetailVO = new CmsUserMobileSeckillDetailVO();
		cmsUserMobileSeckillDetailVO.setItemStoreId(2L);
		cmsUserMobileSeckillDetailVO.setOrderSort(2);
		cmsMobileSeckill.addModuleData(cmsUserMobileSeckillDetailVO);
		cmsUserMobileSeckillDetailVO = new CmsUserMobileSeckillDetailVO();
		cmsUserMobileSeckillDetailVO.setItemStoreId(3L);
		cmsUserMobileSeckillDetailVO.setOrderSort(3);
		cmsMobileSeckill.addModuleData(cmsUserMobileSeckillDetailVO);


		// 团购模块
		CmsUserMobileJoingroupVO cmsMobileJoingroup = new CmsUserMobileJoingroupVO();
		cmsMobileJoingroup.setEndTime("1646096260000");
		cmsMobileJoingroup.setModuleType("5");
		cmsMobileJoingroup.setOrderSort(5);
		CmsUserMobileJoingroupDetailVO cmsUserMobileJoingroupDetailVO = new CmsUserMobileJoingroupDetailVO();
		cmsUserMobileJoingroupDetailVO.setItemStoreId(1L);
		cmsUserMobileJoingroupDetailVO.setOrderSort(1);
		cmsMobileJoingroup.addModuleData(cmsUserMobileJoingroupDetailVO);
		cmsUserMobileJoingroupDetailVO = new CmsUserMobileJoingroupDetailVO();
		cmsUserMobileJoingroupDetailVO.setItemStoreId(2L);
		cmsUserMobileJoingroupDetailVO.setOrderSort(2);
		cmsMobileJoingroup.addModuleData(cmsUserMobileJoingroupDetailVO);
		cmsUserMobileJoingroupDetailVO = new CmsUserMobileJoingroupDetailVO();
		cmsUserMobileJoingroupDetailVO.setItemStoreId(3L);
		cmsUserMobileJoingroupDetailVO.setOrderSort(3);
		cmsMobileJoingroup.addModuleData(cmsUserMobileJoingroupDetailVO);

		// 专区模块
		CmsUserMobileSpecialAreaVO cmsMobileSpecialArea = new CmsUserMobileSpecialAreaVO();
		cmsMobileSpecialArea.setModuleType("7");
		cmsMobileSpecialArea.setOrderSort(7);
		cmsMobileSpecialArea.setTitle("专区标题");
		cmsMobileSpecialArea.setTagName("专区标签");
		cmsMobileSpecialArea.setBackgroundUrl("http://image.com");
		CmsUserMobileSpecialAreaDetailVO cmsUserMobileSpecialAreaDetailVO = new CmsUserMobileSpecialAreaDetailVO("左标题", "左营销文案", 1, "左链接地址", "右标题", "右营销文案", 2, "右链接地址", 1);
		cmsMobileSpecialArea.addModuleData(cmsUserMobileSpecialAreaDetailVO);
		cmsUserMobileSpecialAreaDetailVO = new CmsUserMobileSpecialAreaDetailVO("左标题", "左营销文案", 1, "左链接地址", "右标题", "右营销文案", 2, "右链接地址", 1);
		cmsMobileSpecialArea.addModuleData(cmsUserMobileSpecialAreaDetailVO);


		// 多列商品
		CmsUserMobileItemVO cmsMobileItem = new CmsUserMobileItemVO();
		cmsMobileItem.setModuleType("8");
		cmsMobileItem.setOrderSort(8);
		cmsMobileItem.setTitle("商品楼层标题");
		cmsMobileItem.setTagName("商品楼层标签");
		cmsMobileItem.setPictureUrl("http://背景图地址");
		cmsMobileItem.setLinkType(1);
		cmsMobileItem.setLinkUrl("背景图跳转链接");
		CmsUserMobileItemDetailVO cmsUserMobileItemDetailVO = new CmsUserMobileItemDetailVO();
		cmsUserMobileItemDetailVO.setItemId(1L);
		cmsUserMobileItemDetailVO.setStoreIds("1001,1002,1003");
		cmsUserMobileItemDetailVO.setOrderSort(1);
		cmsMobileItem.addModuleData(cmsUserMobileItemDetailVO);
		cmsUserMobileItemDetailVO = new CmsUserMobileItemDetailVO();
		cmsUserMobileItemDetailVO.setItemId(2L);
		cmsUserMobileItemDetailVO.setStoreIds("2001,2002,2003");
		cmsUserMobileItemDetailVO.setOrderSort(2);
		cmsMobileItem.addModuleData(cmsUserMobileItemDetailVO);
		cmsUserMobileItemDetailVO = new CmsUserMobileItemDetailVO();
		cmsUserMobileItemDetailVO.setItemId(3L);
		cmsUserMobileItemDetailVO.setStoreIds("3001,3002,3003");
		cmsUserMobileItemDetailVO.setOrderSort(3);
		cmsMobileItem.addModuleData(cmsUserMobileItemDetailVO);


		List<Object> cmsFloorList = new ArrayList<>();
		cmsFloorList.add(cmsMobileNavigation);  //导航
		cmsFloorList.add(cmsMobileBannerVO);  //轮播图
		cmsFloorList.add(cmsMobileGraphicNavigation);  //图文导航
		cmsFloorList.add(cmsMobileSpecialPerformance);  // 专场
		cmsFloorList.add(cmsMobileSeckill);  // 秒杀
		cmsFloorList.add(cmsMobileJoingroup);  // 团购
		cmsFloorList.add(cmsMobileSpecialArea); // 专区
		cmsFloorList.add(cmsMobileItem);  // 多列商品
		cmsUserMobileIndexVO.setCmsFloorList(cmsFloorList);

		for (Object obj : cmsFloorList) {
			if (null != obj && obj instanceof CmsUserSpecialPerformanceVO) {
				CmsUserSpecialPerformanceVO cmsSpecialPerformanceResult = (CmsUserSpecialPerformanceVO) obj;
				System.out.println(JSON.toJSON(cmsSpecialPerformanceResult));
			}
		}

		return ResultModel.newSuccess(cmsUserMobileIndexVO);
	}

}
